import actionTypes from './actionTypes'
import { getRobustnessGraph } from '../services'


const startFetchRobustnessGraph = () => {
    return {
        type: actionTypes.START_FETCH_ROBUSTNESS_GRAPH
    }
}

const fetchRobustnessGraphSuccess =  (payload) => {
    return {
        type: actionTypes.FETCH_ROBUSTNESS_GRAPH_SUCCESS,
        payload
    }
}

const fetchRobustnessGraphFailed = () => {
    return {
        type: actionTypes.FETCH_ROBUSTNESS_GRAPH_FAILED
    }
}

export const fetchRobustnessGraph = () => dispatch => {
    dispatch(startFetchRobustnessGraph())
    getRobustnessGraph()
        .then(response => {
            console.log(response)
            if(response.status === 200) {
                dispatch(fetchRobustnessGraphSuccess({ graph: response.data.data }))
            } else {
                dispatch(fetchRobustnessGraphFailed())
            }
        })
        .catch(error => {
            console.log(error)
            dispatch(fetchRobustnessGraphFailed())
        })
}